#{extends 'CRUD/layout.html' /}
<head>
<script type="text/javascript"
	src="/../../../public/javascripts/jquery.min.js"></script>
<script type="text/javascript"
	src="/../../../public/javascripts/jquery-ui.min.js"></script>
<script type="text/javascript">
	$(function() {
		document.getElementById('logCounter').value = "0";
		javascript: fillLogView();
	});
</script>

<script type="text/javascript">
	function fillLogView() {
		$
				.getJSON(
						'@{SystemAdmin.viewLog()}',
						function(data) {
							for ( var i = 0; i < data.length; i++) {
								if (data[i] != null) {
									var innerList = data[i].split("QQQ");
									if (innerList[1] != null) {
										document.getElementById('logTable').innerHTML += "<tr class=\""
												+ document
														.getElementById('logTurn').value
												+ "\"><td>"
												+ innerList[0]
												+ "</td><td>"
												+ innerList[1]
												+ "</td></tr>";
										if (document.getElementById('logTurn').value == "odd") {
											document.getElementById('logTurn').value = "even";
										} else {
											document.getElementById('logTurn').value = "odd";
										}
									}
								}
							}
							document.getElementById('logCounter').value = data.length;

							document.getElementById('crudListPagination').innerHTML = "<p class=\"crudCount\">"
									+ document.getElementById('logCounter').value
									+ " Log Results</p>";
						});
	}
</script>
<script type="text/javascript">
	function attachSearch() {
		var temp = parseInt(document.getElementById('counter').value);
		document.getElementById('logSearchDiv').innerHTML += "<div><select id=\"searchList"+temp+"\">"
				+ "<option>IdeaDeveloper</option>"
				+ "<option>Organization</option>"
				+ "<option>Entity</option>"
				+ "<option>Topic</option>"
				+ "<option>Idea</option>"
				+ "<input id=\"searchText"+temp+"\" type=\"text\" size=\"25\" id=\"searchText\""+temp+""
				+"style=\"width: auto; margin-left: 17px\">&nbsp;<a style=\"font-size: x-small\" href=\"#\""
				+ "onclick=\"this.parentNode.parentNode.removeChild(this.parentNode); return false\">Remove</a></div>";
		var temp = parseInt(document.getElementById('counter').value);
		temp = temp + 1;
		document.getElementById('counter').value = temp;
	}
</script>
<script type="text/javascript">
	function searchInput() {
		var result = "";
		for ( var i = 0; i < document.getElementById('counter').value; i++) {

			if (document.getElementById('searchText' + i + '') != null) {

				if (document.getElementById('searchText' + i + '').value != "") {

					result += document.getElementById('searchList' + i + '').value
							+ ",";
					result += document.getElementById('searchText' + i + '').value
							+ "AAA";
				}
			}
		}
		if (result == "") {
		} else {
			$
					.getJSON(
							'@{SystemAdmin.multiSearch()}',
							{
								'searchInput' : result
							},
							function(data) {
								for ( var i = 0; i < data.length; i++) {
									for ( var u = 0; u <= document
											.getElementById('logCounter').value - 1; u++) {
										document.getElementById('logTable')
												.deleteRow(1);
									}
									var innerList = data[i].split("QQQ");
									document.getElementById('logCounter').value = 0;
									document.getElementById('logTable').innerHTML += "<tr class=\""
											+ document
													.getElementById('logTurn').value
											+ "\"><td>"
											+ innerList[0]
											+ "</td><td>"
											+ innerList[1]
											+ "</td></tr>";
									if (document.getElementById('logTurn').value == "odd") {
										document.getElementById('logTurn').value = "even";
									} else {
										document.getElementById('logTurn').value = "odd";
									}
								}
								if (data[0] != "No results matching your search critirea!") {
									document.getElementById('logCounter').value = data.length;
								} else {
									document.getElementById('logCounter').value = 0;
								}
								document.getElementById('crudListPagination').innerHTML = "<p class=\"crudCount\">"
										+ document.getElementById('logCounter').value
										+ " Log Results</p>";
							});
		}
	}
</script>
</head>

<body>
	<input type="hidden" value="0" id="counter">
	<input type="hidden" value="0" id="logCounter">
	<input type="hidden" value="0" id="searchCounter">
	<input type="hidden" value="odd" id="logTurn">
	<div id="crudContent">
		<!-- LOGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG -->
		<div id="logSearchDiv">
			<a href="javascript:attachSearch()" id="addSearchBar">Add Search
				Area</a> <a href="javascript:searchInput()" id="searchBtn">Search</a>
		</div>

		<div id="content">
			<table id="logTable" width="200" border="1">
				<thead>
					<tr>
						<th>Log Table</th>
						<th>Date</th>
					</tr>
				</thead>
			</table>
			<div id="crudListPagination"></div>
			<p>&nbsp;</p>
		</div>

	</div>
</body>